//
//  MHSetCirclePriceViewController.m
//  MiaoCircle
//
//  Created by 许正荣 on 2018/4/19.
//  Copyright © 2018年 acgera. All rights reserved.
//

#import "MHSetCirclePriceViewController.h"
#import "MHSetCirclePriceViewModel.h"
#import "MHPriceRange.h"
@interface MHSetCirclePriceViewController ()

@property(nonatomic, strong) MHSetCirclePriceViewModel *viewModel;
@property (weak, nonatomic) IBOutlet UITextField *priceTextField;
@property (weak, nonatomic) IBOutlet UILabel *tipsLable;
@property(nonatomic, strong) MHPriceRange *range;

@end

@implementation MHSetCirclePriceViewController
@dynamic viewModel;
- (void)viewDidLoad {
    [super viewDidLoad];
    YYCache *cache=[YYCache cacheWithName:MHCacheGlobleKey];
    MHPriceRange *range = [cache objectForKey:MHCirclePriceRange];
    
    if (!range) {
        range = [MHPriceRange new];
        range.minPrice = 10;
        range.maxPrice = 10000;
    }
    self.range = range;
//    NSMutableAttributedString *mutableAttString = [[NSMutableAttributedString alloc] init];
//    （可设置50~3000的整数）8E8E8E FE7567
//    @{NSBackgroundColorAttributeName:[UIColor colorFromHexString:@"#8e8e8e"]};
//    @{NSFontAttributeName:[UIFont systemFontOfSize:14]};
    NSAttributedString *str1 = [[NSAttributedString alloc]initWithString:@"可设置" attributes:@{NSForegroundColorAttributeName:[UIColor colorFromHexString:@"#8e8e8e"],NSFontAttributeName:[UIFont systemFontOfSize:14]}];

    NSAttributedString *str2= [[NSAttributedString alloc]initWithString:[NSString stringWithFormat:@"%.0f~%.0f",(CGFloat)range.minPrice,(CGFloat)range.maxPrice] attributes:@{NSForegroundColorAttributeName:[UIColor colorFromHexString:@"#FE7567"],NSFontAttributeName:[UIFont systemFontOfSize:14]}];
     NSAttributedString *str3 = [[NSAttributedString alloc]initWithString:@"元" attributes:@{NSForegroundColorAttributeName:[UIColor colorFromHexString:@"#8e8e8e"],NSFontAttributeName:[UIFont systemFontOfSize:14]}];
    
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@""];
    [string appendAttributedString:str1];
    [string appendAttributedString:str2];
    [string appendAttributedString:str3];
    self.tipsLable.attributedText = string;

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
    
   
    // Dispose of any resources that can be recreated.
}

-(void)rightButtonClick
{
  self.viewModel.info.joinPrice =  [self.priceTextField.text doubleValue];

    if (self.viewModel.info.joinPrice <self.range.minPrice || self.viewModel.info.joinPrice > self.range.maxPrice ) {
        [MBProgressHUD mh_showTips:@"输入范围有误"];
        return;
    }
    
    
    if (self.viewModel.info.joinPrice > 0) {
        [self.viewModel.nextCommand execute:nil];
    }
}

@end
